﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EffectController : MonoBehaviour {
    public bool activeSelectEffect=true,activeAttackRangeEffect=true;
    public GameObject selectEffect, attackRangeEffect;
    private AttackRange attackRange;
    public static EffectController Instance;
    private void Awake()
    {
        Instance = this;
    }
    public void Start()
    {
        if (activeAttackRangeEffect)
        {
            Cameracontroller.selectTower += ActiveAttackRange;
            Cameracontroller.exitSelectTower += HideAttackRange;
            attackRangeEffect= Instantiate(attackRangeEffect, new Vector3(10000, -10000, 10000), attackRangeEffect.transform.rotation, transform);  
            attackRange=attackRangeEffect.GetComponent<AttackRange>();
        }
        if (activeSelectEffect)
        {
            Cameracontroller.selectTower += ActiveVFX;
            Cameracontroller.exitSelectTower += HideVFX;
            selectEffect= Instantiate(selectEffect,new Vector3(10000,-10000,10000), selectEffect.transform.rotation,transform);
        }

    }

    public void Update()
    {
        if (attackRangeEffect.activeSelf)
        {
            if (Input.GetMouseButtonDown(0)){
                attackRangeEffect.SetActive(false);
            }
        }
        
    }

    private void HideVFX(TowerBase obj)
    {
        selectEffect.SetActive(false);
    }

    private void ActiveVFX(TowerBase obj)
    {
        selectEffect.transform.position = obj.transform.position;
        selectEffect.SetActive(true);
    }
    private void HideAttackRange(TowerBase obj)
    {
        attackRange.Hide();
    }

    private void ActiveAttackRange(TowerBase obj)
    {
        if(!obj.GetTower){
            return;
        }
        attackRange.SetAttackRange(obj.GetTower.attackRange,obj.transform.position+Vector3.up*0.5f);
    }
}
